/**
 * Node属性：
 * index - used to store the order of nodes within their parent. When a node is inserted or removed, all of its sibling nodes after the insertion or removal point will have their indexes updated. If desired, the application can use this field to persist the ordering of nodes.
 * 		   However, if the server uses a different method of storing order, it may be more appropriate to leave the index field as non-persistent. When using a WebStorage Proxy if storing order is required, this field must be overridden to be persistent.
 * 		   Also if client-side sorting is being used it is recommended for the index field to be left as non-persistent, since sorting updates the indexes of all the sorted nodes, which would cause them to be persisted on next sync or save if the persist property is true.
 * depth - used to store the depth of a node in the tree hierarchy. Override this field to turn on persistence if the server needs to store the depth field. When using a WebStorage Proxy it is recommended to not override the persistence of the depth field since it is not needed to properly store the tree structure and will just take up extra space.
 * checked - this field should be overridden to be persistent if the tree is using the checkbox feature
 * expanded - used to store the expanded/collapsed state of a node. This field should not normally need to be overridden.
 * expandable - used internally to indicate that this node is expandable. Do not override the persistence of this field.
 * cls - used to apply a CSS class to the node when it is rendered in a TreePanel. Override this field to be persistent if desired.
 * iconCls - used to apply a css class to the node’s icon when it is rendered in a TreePanel. Override this field to be persistent if desired.
 * icon - used to apply a custom icon to the node node when it is rendered in a TreePanel. Override this field to be persistent if desired.
 * root - used to indicate that this node is the root node. This field should not be overridden.
 * isLast - used to indicate that this node is the last of its siblings. This field should not normally need to be overridden.
 * isFirst - used to indicate that this node is the first of its siblings. This field should not normally need to be overridden.
 * allowDrop - used internally to deny dropping on the node. Do not override the persistence of this field.
 * allowDrag - used internally to deny dragging the node. Do not override the persistence of this field.
 * loaded - used internally to indicate that the node’s children have been loaded. Do not override the persistence of this field.
 * loading - used internally to indicate that the proxy is in the process of loading the node’s children. Do not override the persistence of this field.
 * href - used to specify a url that the node should be a link to. Override to be persistent if desired.
 * hrefTarget - used to specify the target for the href. Override to be persistent if desired.
 * qtip - used to add a tooltip text to the node. Override to be persistent if desired.
 * qtitle - used to specify the title for the tooltip. Override to be persistent if desired.
 * children - used internally when loading a node and its children all in one request. Do not override the persistence of this field.
 */
Ext.define('sysResource', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'text', type: 'string' },
        { name: 'resourceCode', type: 'string' },
        { name: 'resourceUrl', type: 'string' },
        { name: 'isMenu', type: 'string' },
        { name: 'resourceId', type: 'int' }
    ],
    proxy: {
        type: 'ajax',
        api: {
            create: '/admin/sysResource/addSysResource.json',
            read: '/admin/sysResource/readResource.json',
            update: '',
            destroy: ''
        }
    }

});

var store = Ext.create('Ext.data.TreeStore', {
    model: 'sysResource',
    root: {
        name: 'root',
        expanded: true
    }
});

/**
 * create
 */
//var newPerson = Ext.create('sysResource', { name: 'Nige', leaf: true });
//store.getNodeById(2).appendChild(newPerson);
//newPerson.save();

/**
 * update
 */
//store.getNodeById(1).set('name', 'Philip');

/**
 * delete
 */
//store.getRootNode().lastChild.remove();

/**
 * 同步
 * After creating, updating, and removing several nodes, they can all be persisted in one operation by calling the TreeStore’s sync() method:
 */
//store.sync();

var tree = Ext.create('Ext.tree.Panel', {
	    title: '系统资源管理',
	    region : 'center',
	    store: store,
	    rootVisible : false,
	    forceFit : true,
	    rowLines : true,
		columnLines : true,
	    fields: ['text'],
	    columns: [{
	        xtype: 'treecolumn',
	        width: 300,
	        text: '资源名称',
	        dataIndex: 'text',
	        sortable: true
	    }, {
	        text: '资源编码',
	        dataIndex: 'resourceCode',
	        flex: 1,
	        sortable: true
	    }
	    , {
	        text: 'URL地址',
	        dataIndex: 'resourceUrl',
	        flex: 2,
	        sortable: true
	    }, {
	        text: '菜单',
	        dataIndex: 'isMenu',
	        flex: 1,
	        sortable: true
	    }
	    ]
	});